<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class AlbumAddPost extends FormRequest
{
    private $userId = null;
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        $this->userId = auth('api')->user()->id;
        return $this->userId;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name'=>'bail|required|min:1|max:11|unique:albums,name,'.$this->userId.'user_id,',
        ];

    }

    /**
     * 获取已定义的验证规则的错误消息。
     *
     * @return array
     */
    public function messages()
    {
        return [
            'name.required' => '专辑名称不能为空',
            'name.min' => '专辑名称最少1个字',
            'name.max' => '专辑名称最多11个字',
            'name.unique' => '存在同名的专辑',
        ];
    }
}
